home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3893 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.chattanooga.net!usenet
  2. From: "Eric W. Bradway" <ebradway@microsports.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem...Problem!
  5. Date: Wed, 31 Jan 1996 13:16:55 -0500
  6. Organization: Micro Sports, Inc.
  7. Message-ID: <310FB217.280C@microsports.com>
  8. References: <4el09q$6im@ratree.psu.ac.th>
  9. NNTP-Posting-Host: 205.244.28.38
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (Win95; I)
  14.  
  15. Sanon CHAOCHAIYAPORN wrote:
  16. > #define NUM 8
  17. > #define ERR 1e-4
  18.  
  19. Try avoiding the scientific notation by doing a divide by 10000 and 
  20. comparing to 1. I assume this isn't a time-critical routine so the extra 
  21. divide won't hurt. If it is time-critical, rewrite the program using 
  22. long ints.
  23.  
  24. >     v[i]   = (v[i+1] + v[i+2]) / 8;
  25. >     v[i+1] = (v[i] + v[i+3] + 40) / 8;
  26. >     v[i+2] = (v[i] + v[i+3] + v[i+5] + 50) / 8;
  27. >     v[i+3] = (v[i+1] + v[i+2] + 110) / 8;
  28. >     v[i+4] = (v[i+5] + v[i+6] + 150) / 8;
  29. >     v[i+5] = (v[i+2] + v[i+4] + v[i+7] + 70) / 8;
  30. >     v[i+6] = (v[i+4] + v[i+7] + 200) / 8;
  31. >     v[i+7] = (v[i+5] + v[i+6] + 200) / 8;
  32.  
  33. Your problem may lie here - add a .0 to each numeric constant (e.g., 
  34. 8.0, 40.0, 110.0) to get the compiler to treat them as floats. Many 
  35. compilers automatically convert everything to ints if you don't 
  36. specifically show that the values/variables are floats.
  37.  
  38. And of course, on closer inspection, when do you assign meaningful 
  39. values to v[]? Do you mean to initialize to zero and get the following 
  40. results on the first pass:
  41. v[0] = 0
  42. v[1] = 5
  43. v[2] = 6.25
  44. v[3] = 14.53125
  45. v[4] = 18.75
  46. v[5] = 11.875
  47. v[6] = 27.34375
  48. v[7] = 29.90234
  49.  
  50. You seem to be making your program much more complex than necessary!
  51.  
  52. -Eric
  53.